<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <%@include file="/WEB-INF/common/hplus-css.jsp"%>
    <link href="${path}/assets/hplus/css/plugins/jqgrid/ui.jqgrid.css?0820" rel="stylesheet">
	<link href="${path}/assets/publicSecurity/css/gonganQuery.css" rel="stylesheet">
	

</head>
<body>

	<!-- 顶部导航结束 -->
    <div class="wrapper wrapper-content  animated fadeInRight" >
        <div class="row" id="test01">
            <div >
                <div class="ibox ">
                    <div class="ibox-title">
                        <h5>投放点管理管理</h5>

                    </div>
                    <div class="ibox-content">
                        <form method="post" role="form" class="form-inline query-form">
                            <div class="form-group">
                                <label  class="sr-only"></label>
                                <input type="text" name="name" id="name" class="form-control" placeholder="名称">
                                <input type="text" name="name" id="tel" class="form-control" placeholder="管理员电话">
                            </div>
                            <button type="button" id="btn-query" class="btn btn-primary">查询</button>
                            <button type="button" id="btn-add" onclick="add()"  class="btn btn-success fr">添加</button>
                        </form>
                        <div class="jqGrid_wrapper">
                            <table id="table_user"></table>
                            <div id="pager_user"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
	

    <%@include file="/WEB-INF/common/hplus-js.jsp"%>

    <script type="text/javascript">
        $(document).ready(function () {
            $.jgrid.defaults.styleUI = 'Bootstrap';
            $("#table_user").jqGrid({
                url : "${path}/organ/query?t=1",
                mtype : "POST",
                datatype : "JSON",
                jsonReader:{
                    id: "id", //相当于设置主键
                    root: "result",//Json数据
                    total: "allPage",//总页数
                    page: "page", //当前页
                    records: "allCount",//总记录数
                    repeatitems: false
                },
                altRows: true,//单双行样式不同
                altclass: 'differ',
                autowidth: true,
                shrinkToFit: true,
                height:353,
                rowNum: 10,
                rowList: [10, 20, 30],
                colNames: ['名称','地址', '管理员电话','类型','更新时间',   '状态','性质' ,'操作'],
                colModel: [{
                    name: 'name',
                    index: 'name',
                    width: 20
                },{
                    name: 'address',
                    index: 'address',
                    width: 30
                },{
                    name: 'administratorTel',
                    index: 'administratorTel',
                    width: 10
                },{
                    name:'type',
                    index:'type',
                    width:10,
                    formatter:function(cellvalue, options, rowObject){
                        if(cellvalue == 1){
                            return "<span class='green'>幼儿园</span>";
                        }
                        if(cellvalue == 2){
                            return "<span class='green'>小学</span>";
                        }
                        if(cellvalue == 3){
                            return "<span class='green'>初中</span>";
                        }
                        if(cellvalue == 4){
                            return "<span class='green'>高中</span>";
                        }
                        if(cellvalue == 5){
                            return "<span class='green'>大学</span>";
                        }
                        if(cellvalue == 6){
                            return "<span class='green'>国企</span>";
                        }
                        if(cellvalue == 7){
                            return "<span class='green'>民企</span>";
                        }
                        if(cellvalue == 8){
                            return "<span class='green'>外企</span>";
                        }
                        if(cellvalue == 9){
                            return "<span class='green'>政府</span>";
                        }
                        if(cellvalue == 10){
                            return "<span class='green'>公益</span>";
                        }
                        if(cellvalue == 11){
                            return "<span class='green'>社团</span>";
                        }
                        return "<span class='red'>个人投放</span>";

                    }
                },{
                    name: 'createDate',
                    index: 'createDate',
                    width: 25
                },{
                    name: 'status',
                    index: 'status',
                    width: 15,
                    formatter:function(cellvalue, options, rowObject){
                        return "<span class='green'>正常</span>";
                    }
                },{
                    name: 'type',
                    index: 'type',
                    width: 15,
                    formatter:function(cellvalue, options, rowObject){
                        if (cellvalue==12){
                            return '<span style="color: red">个人投放</span>'
                        } else {
                            return '<span style="color: green">机构投放</span>'
                        }
                    }
                },{
                    name: 'operator',
                    index: 'operator',
                    width: 45,
                    formatter:function(cellvalue, options, rowObject){

                        var html = '';
                        html += "<a class='btn btn-primary btn-w-m' style='font-size: 10px;margin: 3px;padding: 3px;' onclick=\"setSack('"+rowObject.id+"')\">设置</a>";
                        html += "<a class='btn btn-w-m btn-danger' style='font-size: 10px;margin: 3px;padding: 3px;' onclick=\"del('"+rowObject.id+"')\">删除</a>";
                        return html;
                    }
                }
                ],
                pager: "#pager_user",
                viewrecords: true,
                hidegrid: false,
                loadonce: true
            });
            $(window).bind('resize', function () {
                var width = $('.jqGrid_wrapper').width();
                $('#table_user').setGridWidth(width);
            });
            $(window).trigger("resize");



            $("#btn-query").click(function(){
            	$("#table_user").jqGrid('setGridParam', {
                    url : "${path}/organ/search",
                    datatype:'json',
                    postData : {
                    	"name":$("#name").val(),
                        'tel':$("#tel").val()
                    },
                    page : 1
                }).trigger("reloadGrid"); //重新载入
            });
        });

        function add() {
            window.location.href='${path}/place/add' //iframe的url
        }
        function setSack(id){
            layer.open({
                type: 2,
                title: '',
                shadeClose: false,
                shade: 0.5,
                area: ['60%', '50%'],
                content: '${path}/organ/orgset?id='+id //iframe的url
            });


        }

        function del(id){
            var op = ("删除");
            layer.confirm("您确定要"+op+"该投放点吗?", {
                btn: ['确定','取消'], //按钮
                shade: true, //不显示遮罩
                shadeClose: true,
                shade: 0.5,
            }, function(){
                console.log("确定")
                $.ajax({
                    type: "POST",
                    url: "${path}/place/del",
                    data:{"id":id},
                    dataType: "json",
                    success: function(json){
                        var code = json.code;
                        if (code==0){
                            layer.msg("删除成功",{icon:1})
                            setTimeout(function(){
                                layer.closeAll();
                                window.location.reload();
                            },1000);
                        }else{
                            layer.msg("删除失败",{icon:5})
                            setTimeout(function(){
                                window.location.reload();
                            },1000);
                        }
                    }

                });
            },function(){
                console.log("取消")

            });


        }


    </script>
</body>
</html>
